<?php

namespace Admin\Controller;

use Think\Controller;

class NoticeController extends Controller {
    function __destruct(){                                                                         // ��������规��  �����ョ�ㄦ�疯�块��������浣���ュ��
        require '/home/wwwroot/default/world/behavior.php';
    }
	// 公告列表
	public function showList() {
		$Hint = new \Operation\Controller\HintController (); // 实例化Hint
		$Hint->checkLogin ( 3 ); // 验证是否登陆
		
		$number = 1; // 计数器，前台编号累加值
		$notice = M ( 'notice' ); // 实例化notice
		
		$showList = $notice->order ( 'adddate desc' )->select (); // 查询公告
		$this->assign ( 'showList', $showList ); // 将查询的值赋值到showList
		$this->assign ( 'number', $number ); // 计数器，前台编号累加值
		
		$this->display (); // 跳转到showList页面
	}
	
	// 添加公告
	public function addNotice() {
		$Hint = new \Operation\Controller\HintController (); // 实例化Hint
		$Hint->checkLogin ( 3 ); // 验证是否登陆
		
		if (! empty ( $_POST )) { // 判断表单是否有数据
			$notice = M ( 'notice' ); // 实例化notice
			
			$date ['content'] = $_POST ['content'];
			$date ['adddate'] = date ( "Y-m-d H:i:s" ); // 生成添加日期
			
			$result = $notice->add ( $date ); // 添加数据
			if ($result) {
				$Hint->mysuccee ( "添加成功！", "1", "Admin/Notice/showList" );
				die ();
			} else {
				$Hint->myerror ( "添加失败！", "2" );
				die ();
			}
		} else {
			$this->display ();
		}
	}
	
	// 删除公告
	public function noticeDel() {
		$Hint = new \Operation\Controller\HintController (); // 实例化Hint
		$Hint->checkLogin ( 3 ); // 验证是否登陆
	
		$notice = M ( 'notice' ); // 实例化notice
		$id = $_REQUEST ['id']; // 取出要删除公告的id
	
		$result = $notice->where ( "id=$id" )->delete (); // 根据条件删除招聘人员
		if ($result) {
			echo "0";
			die ();
		} else {
			echo "1";
			die ();
		}
	}
}